package com.jereh.zk.oa.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jereh.zk.oa.dao.EmpDao;
import com.jereh.zk.oa.dao.baseDao;
import com.jereh.zk.oa.entity.Voucher;
import com.jereh.zk.oa.entity.VoucherDetail;
import com.jereh.zk.oa.entity.VoucherType;

public class EmpDaoImpl extends baseDao implements EmpDao {

	public int insertVoucher(Voucher v) {
		String sql1="insert voucher values(?,?,?,?,?,?)";
		List params1=new ArrayList();
		params1.add(v.getAdd_user());
		params1.add(v.getUser_id());
		params1.add(v.getCreate_time());
		params1.add(v.getState());
		params1.add(v.getDescripton());
		params1.add(v.getAmount());
		int ret=super.executeUpdate(sql1, params1);
		return ret;
	}

	public int insertVoucherDetail(VoucherDetail vd) {
		String sql="insert voucherdetail values(?,?,?,?)";
		List params=new ArrayList();
		params.add(vd.getItem_name());
		params.add(vd.getItem_money());
		params.add(vd.getItem_descrip());
		params.add(vd.getVoucher_id());
		int ret=super.executeUpdate(sql, params);
		return ret;
	}

	public int selectVoucherId() {
		String sql="select max(id) as mid from voucher";
		int ret=0;
		ResultSet rs=super.executeQuery(sql);
		try {
			while(rs.next()){
				ret=rs.getInt("mid");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				rs.close();super.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return ret;
	}
}
